#ifndef _STACK_H_
#define _STACK_H_

/**********************************
write by zhangliang  <liangzhws@foxmail.com>
**********************************/

#include "list.h"

/*********************************
stack model:
	    ------
stack head | head |
            ------\
                   \
                    >  ------
                      | stack  ...  |
                       ------
*********************************/
#ifdef _DLIST_T
#define _STACK_T
typedef dlist_t stack_t;

#ifdef _DLIST_S
#define _STACK_S
#define stack_s dlist_s

#define init_head_stack_t(head) init_head_dlist_t(head)

/**
  @name: stack_is_empty
  @function: judge the stack is empty or not
  @param: #const list_t * head# stack head
  @return: #bool# true is represent for empty stack, false is represent for not empty stack
  @algorithm complexity: O(1)
*/
bool stack_is_empty(const stack_t * head);

/**
  @name: stack_push
  @function: push one entry into last of the stack use the rule of stack
  @param: #stack_t * head# the head of the stack
  @param: #stack_t * entry# the entry of want to be pushed
  @return: #void#
  @algorithm complexity: O(1)
*/
void stack_push(stack_t * head, stack_t * entry);

/**
  @name: stack_pop
  @function: get the last entry from the stack and delete this one
  @param: #stack_t * head# the head of the stack
  @return #stack_t *# the last entry for the stack or null represent noting can be get
  @algorithm complexity: O(1)
*/
stack_t * stack_pop(stack_t * head);

/**
  @name: stack_empty
  @function: empty the stack
  @param: #stack_t * head# the head of the stack
  @return #void#
  @algorithm complexity: O(1)
*/
void stack_empty(stack_t * head);

/**
  @name: stack_is_exist
  @function: judge entry in stack head or not
  @param: #const stack_t * head# stack head
  @param: #const stack_t * entry# stack unit
  @return: #bool# true is exist and false is not exist
  @algorithm complexity: O(n)
*/
bool stack_is_exist(const stack_t * head, const stack_t * entry);
#endif /* _DLIST_S */ 
#endif /* _DLIST_T */


#endif /* _STACK_H_ */
